package com.laowang.framework.listener;

import com.laowang.common.exception.CustomException;
import com.laowang.common.utils.PayUtil;
import com.laowang.project.pay.config.MyWxPayConfigUtil;
import com.laowang.project.system.domain.WxUser;
import com.laowang.project.system.domain.vo.ObjectData;
import com.laowang.project.system.service.WxOrderService;
import com.laowang.project.system.service.WxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Auther laowang
 * @Date 2024/3/15
 * @Description  定义监听器
 */

@Component
public class EventListener implements ApplicationListener<ApplicationEvent> {

    @Autowired
    private WxUserService wxUserService;

    @Autowired
    private WxOrderService wxOrderService;

    @Autowired
    private UtilMoney utilMoney;

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
        Event e = (Event) event;
        System.out.println("收到事件：" + e);
        if (e.getEventType().equals(1)){
            WxUser wxUser1 = (WxUser) event.getSource();
            //wxUserService.updateWxUser(wxUser1);
            wxUserService.updateWxUserNull(wxUser1);
        }
        //退款
        if (e.getEventType().equals(2)){
            System.out.println("退款事件");
            ObjectData objectData = (ObjectData) event.getSource();
            //wxUserService.updateWxUser(wxUser1);
            //utilMoney.refound111(objectData.getWxOrder(),objectData.getMyCyhActivity());
        }

        if (e.getEventType().equals(3)){
            System.out.println("退款事件");
            MyWxPayConfigUtil myWxPayConfigUtil = (MyWxPayConfigUtil) event.getSource();
            System.out.println(myWxPayConfigUtil.getOrderId()+"订单退款");
            Map<String, String> map = PayUtil.test5(myWxPayConfigUtil);
            System.out.println(map);
        }


    }
}
